<?php

namespace App\Models;

use Illuminate\Database\Eloquent\Model;

class StoreLevel extends Model
{
    protected $table = 'store_levels';

    protected $fillable = [
    	'store_level_name',
    	'parant_id',
    	'hotel_id',
        'type_id'
    ];


    protected $appends = [
        'type_desc'
    ];

    public function getTypeDescAttribute() {
        if (array_key_exists('type_id', $this->attributes)) {
            $typeDesc = '';
            $typeDesc = $this->attributes['type_id'] == 1 ?  '送餐服务' : '便利店';
            return $this->attributes['type_id'] = $typeDesc;
        }
    }

    public function hotel(){
    	return $this->belongsTo('App\Models\Hotel');
    }

 	public function parant(){
 		return $this->belongsTo('App\Models\StoreLevel','parant_id','id');
 	}
}
